package com.ars.common.dao.activity;

import com.ars.common.beans.Active.Active;
import com.ars.common.beans.User.User;
import com.ars.common.utils.DBUtil;

import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.sql.Timestamp;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * ClassName: UpdateActivityInfo
 * Package: com.ars.common.dao.activity
 * Description:
 *
 * @Author: Bryan Long
 * @Create: 2024/7/29 - 15:33
 * @Version: v1.0
 */
public class UpdateActivityInfo {
    public static boolean updateActivityInfo (Active activity, int id) throws SQLException, ParseException {
        String sql = "update active set name = ?, beginTime = ?,endTime = ?, type = ? where id = ?";

        PreparedStatement ps = DBUtil.getConnection().prepareStatement(sql);
        ps.setString(1,activity.getName());
//        ps.setString(2,activity.getCreatorID());

        // 定义用于转换的时间格式
        SimpleDateFormat dateTimeFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm");

        // 将字符串时间转换为Timestamp
        Date timeBeginDate = dateTimeFormat.parse(activity.getBeginTime());
        Timestamp beginTimestamp = new Timestamp(timeBeginDate.getTime());

        Date timeEndDate = dateTimeFormat.parse(activity.getEndTime());
        Timestamp endTimestamp = new Timestamp(timeEndDate.getTime());

        // 设置Timestamp参数
        ps.setTimestamp(2, beginTimestamp);
        ps.setTimestamp(3, endTimestamp);

        ps.setString(4, activity.getType());

        ps.setInt(5,id);

        if(ps.executeUpdate() == 1)
        {
            return true;
        }
        else
        {
            return false;
        }


    }
}
